package com.itheima.tlias.service.impl;

import com.itheima.tlias.mapper.ClazzMapper;
import com.itheima.tlias.mapper.EmpMapper;
import com.itheima.tlias.service.ReportService;
import com.itheima.tlias.pojo.ClassOption;
import com.itheima.tlias.pojo.JobOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 11 4月 2025 16:04
 */
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 职位数据统计
     *
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> jobData = empMapper.getEmpJobData();
        List<Object> job = jobData.stream().map(s -> s.get("pos")).collect(Collectors.toList());
        List<Object> data = jobData.stream().map(s -> s.get("value")).collect(Collectors.toList());
        return new JobOption(job, data);
    }

    /**
     * 性别数据统计
     *
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    /**
     * 学历数据统计
     *
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return empMapper.getStudentDegreeData();
    }

    /**
     * 班级人数统计
     *
     * @return
     */
    @Override
    public ClassOption getStudentCountData() {
        List<Map<String, Object>> data = clazzMapper.selectClazzNum();
        List<Object> name = data.stream().map(s -> s.get("name1")).collect(Collectors.toList());
        List<Object> value = data.stream().map(s -> s.get("value")).collect(Collectors.toList());
        return new ClassOption(name, value);
    }
}
